import re

operation = ""
one       = 0
two       = 0

#return if operations is addition
def addition(line):
    return True if re.match(r'::[*]:::[*]::', line) else False

#return if operations is addition
def subtraction(line):
    return True if re.match(r'::::[*]::::', line) else False

#return if operations is addition
def multiplication(line):
    return True if re.match(r"[*]:[*]:::[*]:[*]", line) else False

#function consist on descriptors
def with_iter(iterable):
    with iterable as iter:
        for item in iter:
            yield item

#function find first occurs in string
def findCharInString(str, ch):
    for ltr in str:
        if ltr == ch:
            return str.index(ltr)

#check if first and last line has only :
def checkFirstLastLine(line):
    
    matchObj = re.match( r':(:{7}):', line)

    if matchObj:
        return True
    else:
        return False

#check third line and set operations
def checkThirdLine(line):

    global operation
    
    if addition(line) == True:
        operation = "addition"
        return True
    else:
        if subtraction(line) == True:
            operation = "subtraction"
            return True
        else:
            if multiplication(line) == True:
                operation = "multiplication"
                return True
            else:
                return False
            
#check 2 and 4 line if line has only one *
def CheckTwoFourthLine(line):
    matchObj = re.match( r'([:*]{9})', line)
    
    if matchObj:
        if line.count('*') == 1:
            return True
    else:
        return False

def VerifyFile():
    
    counter = 1
    
    #control sum
    control = False
    
    global one 
    global two
    
    for line in with_iter(open('D:/simplyFile.txt')):

        if counter == 1 or counter == 5:
            
            if checkFirstLastLine(line):
                control = control + 1
        
        if counter == 2:

            #set one digit
            one = findCharInString(line, "*")
            
            if CheckTwoFourthLine(line):
                control = control + 1

        if counter == 4:

            #set two digit
            two = findCharInString(line, "*")
            
            if CheckTwoFourthLine(line):
                control = control + 1

        if counter == 3:    
            if checkThirdLine(line):
                control = control + 1

        counter = counter + 1

    return True if control == 5 else False

if VerifyFile():

    if operation == "addition":
        print one + two

    if operation == "subtraction":
        print one / two

    if operation == "multiplication":
        print one * two




